//
//  CityTableViewController.m
//  quickDoctor
//
//  Created by zhaowei on 17/3/9.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "CityTableViewController.h"
#import "WeatherView.h"

@interface CityTableViewController ()

@end

static NSString *cityCell = @"cityCell";
@implementation CityTableViewController {
    //城市数组
    NSArray *_cityArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI{
    
    self.title = @"选择当前城市位置";
    
    //隐藏返回按钮
    self.navigationItem.hidesBackButton = YES;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_nav_button_back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    //设置左侧箭头颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

    
    //注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cityCell];
}
/// pop操作
- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
    
}



#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    //通过点击的行来取出对应的字典
    NSDictionary *dict = _provinceArr[_rowIndex];
    //取出城市数组
    NSArray *cityArr = dict[@"cities"];
    _cityArr = cityArr;
    
    return cityArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cityCell forIndexPath:indexPath];
    
    
    cell.textLabel.text = _cityArr[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    //发出通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"location" object:nil userInfo:@{@"cityName":_cityArr[indexPath.row]}];
    //pop
    [self.navigationController popToRootViewControllerAnimated:NO];
 
    
    
}
- (void)returnProvinceAndCity:(ReturnBlock)block {
    
    self.returnBlock = block;
}

- (void)viewWillDisappear:(BOOL)animated {
    WeatherView *weatherView = [[WeatherView alloc] init];
    [weatherView loadData];
}

@end
